local spawnMenu = nil
local PANEL = {}

function PANEL:Init()
	spawnMenu = self
	
	self:SetTitle("")
	self:ShowCloseButton(false)
	
	self.Props = vgui.Create("DPanelList", self)
	self.Props:SetDrawBackground(false)
	self.Props:EnableVerticalScrollbar(true)
	self.Props:SetPadding(4)
	self.Props:SetSpacing(4)
	self.Props:EnableHorizontal(true)
	
	for _, v in pairs(props.GetAll()) do
		local prop = vgui.Create("PropIcon")
		prop:SetProp(v)
	
		self.Props:AddItem(prop)
	end
	
	self.Tools = vgui.Create("DHorizontalPanelList", self)
	self.Tools:EnableHorizontalScrollbar()
	self.Tools:SetPadding(4)
	self.Tools:SetSpacing(4)
	for i = 1, 31 do
		self.Tools:AddItem(vgui.Create("ToolIcon"))
	end
	
	-- rmv background
	
	self:PerformLayout()
	self:MakePopup()
end

function PANEL:Paint()
	draw.RoundedBox(4, 0, 0, self:GetWide(), 32, Color(40, 40, 40, 255))
	draw.SimpleText(money.FormatMoney(2).."!", "Flood30", self:GetWide()/2, 16, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

	draw.RoundedBox(8, 0, 40, self:GetWide(), self:GetTall()-188, Color(40, 40, 40, 255))
	draw.SimpleText("Props", "Flood22", 8, 44, colour_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
	
	draw.RoundedBox(8, 0, self:GetTall()-132, self:GetWide(), 132, Color(40, 40, 40, 255))
	draw.SimpleText("Tools", "Flood22", 8, self:GetTall()-128, colour_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
end

function PANEL:PerformLayout()
	self:SetSize(600, 468)
	self:SetPos(ScrW()/2 - self:GetWide()/2, ScrH()/2 - self:GetTall()/2)
	
	self.Props:SetSize(self:GetWide()-32, self:GetTall()-228)
	self.Props:SetPos(16, 72)
	
	self.Tools:SetSize(self:GetWide()-32, 88)
	self.Tools:SetPos(16, self:GetTall()-96)
	
	-- write Tools and Props above.
end

vgui.Register("SpawnMenu", PANEL, "DFrame")

hook.Add("OnSpawnMenuOpen", "Flood_OpenSpawnMenu", function()
	if !spawnMenu or !spawnMenu:IsValid() then
		vgui.Create("SpawnMenu")
	else
		spawnMenu:SetVisible(true)
	end

	gui.EnableScreenClicker(true)
	RestoreCursorPosition()
end)

hook.Add("OnSpawnMenuClose", "Flood_CloseSpawnMenu", function()
	if spawnMenu and spawnMenu:IsValid() and spawnMenu:IsVisible() then
		spawnMenu:SetVisible(false)
	end
	
	RememberCursorPosition()
	gui.EnableScreenClicker(false)
end)